home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / DBL Pascal Library / CheckSum ƒ / Inline Checksum next >
Text File  |  1990-12-11  |  2KB  |  51 lines

  1. program TestCheckSum;
  2.  
  3.     function CheckSum (h: Handle): LONGINT;
  4.     {Returns the sum of all bytes in a handle, ignoring integer overflow.            }
  5.     {A nil handle and an empty handle both return a sum of zero.                        }
  6.     {Inner loop is 34 cycles. Should run at about 7 seconds/MB on a Mac Plus.        }
  7.     {Could be recoded with a 24 cycle inner loop, but would larger and less clear.    }
  8.     inline
  9.         $205F,                         {        move.l (a7)+,a0        ;the handle            }
  10.         $2208,                        {        move.l a0,d1            ;is it nil?                }
  11.         $671A,                        {        beq @3                ;yes - bail out        }
  12.         $A025,                        {        _GetHandleSize        ;size to D0            }
  13.         $4281,                        {        clr.l d1                ;clear accumulator    }
  14.         $4282,                        {        clr.l d2                ;clear byte extender    }
  15.         $2050,                        {        movea.l (a0),a0        ;dereference            }
  16.         $51C8, $000A,                {@1    dbra d0,@2            ;done? (partially)    }
  17.         $0480, $0001, $0000,         {        subi.l $10000,d0        ;yes - fix hi word    }
  18.         $6B06,                        {        bmi @3                ;done? (really)        }
  19.         $1418,                         {@2    move.b (a0)+,d2        ;no, get next byte    }
  20.         $D282,                        {        add.l d2,d1            ;accumulate it        }
  21.         $60EE,                        {        bra @1                ;repeat                }
  22.         $2E81;                        {@3    move.l d1,(a7)        ;tuck result            }
  23.  
  24.     const
  25.         blockSize = $10000;        {64K}
  26.         howMany = 16;            {… times 16 is 1MB}
  27.  
  28.     var
  29.         h: Handle;
  30.         s, t: LONGINT;
  31.         i: INTEGER;
  32.  
  33. begin
  34.     ShowText;
  35.  
  36.     h := GetResource('CODE', 1);
  37.     s := CheckSum(h);
  38.     writeln(s);
  39.  
  40.     h := NewHandleClear(blockSize);
  41.     if h <> nil then
  42.         begin
  43.             t := TickCount;
  44.             for i := 1 to howMany do
  45.                 s := CheckSum(h);
  46.             t := TickCount - t;
  47.             writeln(s, ' ', howMany * blockSize, ' ', t / 60 : 0 : 1);
  48.         end
  49.     else
  50.         writeln('No room for time test.');
  51. end.